/*
 *   Copyright (c) 2010-2022, SIUFUNG
 */
package net.siufung.market.base.permit.controller.model.vo;

import cn.hutool.core.date.DatePattern;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import net.siufung.core.model.AbstractVo;
import net.siufung.core.model.enums.DeletedEnum;

import java.time.LocalDateTime;
import java.util.Objects;

/**
 * @author 陈建峰
 * @since 2022-07-05 16:14:50
 */
@Data
@EqualsAndHashCode(callSuper = true)
@ApiModel(value="RoleVo", description="系统角色表")
public class RoleVo extends AbstractVo {

    private static final long serialVersionUID = -7275811879351452000L;
    /**
     * 主键id
     */
    @ApiModelProperty(value = "主键id")
    private Integer id;

    /**
     * 角色名称
     */
    @ApiModelProperty(value = "角色名称")
    private String roleName;

    /**
     * 角色编码
     */
    @ApiModelProperty(value = "角色编码")
    private String roleCode;

    /**
     * 排序
     */
    @ApiModelProperty(value = "排序")
    private Integer sequence;

    /**
     * 描述
     */
    @ApiModelProperty(value = "描述")
    private String description;

    /**
     * 租户
     */
    @ApiModelProperty(value = "租户")
    private Integer tenantId;

    /**
     * 创建人
     */
    @ApiModelProperty(value = "创建人")
    private String createdBy;

    /**
     * 创建时间
     */
    @ApiModelProperty(value = "创建时间")
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = DatePattern.NORM_DATETIME_PATTERN, timezone = "GMT+8")
    private LocalDateTime createdAt;

    /**
     * 更新人
     */
    @ApiModelProperty(value = "更新人")
    private String updatedBy;

    /**
     * 更新时间
     */
    @ApiModelProperty(value = "更新时间")
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = DatePattern.NORM_DATETIME_PATTERN, timezone = "GMT+8")
    private LocalDateTime updatedAt;

    /**
     * 数据标识
     */
    @ApiModelProperty(value = "数据标识")
    private Boolean deleted;

    /**
     * 使用数量
     */
    @ApiModelProperty(value = "使用数量")
    private Integer userCount = 0;

    /**
     * 赋值权限数量
     */
    @ApiModelProperty(value = "赋值权限数量")
    private Integer permitCount = 0;

    /**
     * 数据标识描述
     * @return  数据标识描述
     */
    @Override
    public String getDeletedDesc(){
        return DeletedEnum.getDesc(deleted);
    }

    @Override
    public boolean getAllowRemove() {
        return (Objects.isNull(userCount)? 0:userCount) == 0;
    }

    @Override
    public boolean getAllowUpdate() {
        return DeletedEnum.NOT.equals(DeletedEnum.get(deleted));
    }

    /**
     * y允许授权
     * @return boolean
     */
    public boolean getAllowAudit() {
        return DeletedEnum.NOT.equals(DeletedEnum.get(deleted));
    }

}